import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { UserController } from './modules/user/user.controller';
import { UserModule } from './modules/user/user.module';
import { AuthModule } from './modules/auth/auth.module';
import { BookController } from './modules/book/book.controller';
import { BookModule } from './modules/book/book.module';
// import { getMySqlUserInfo } from './utils/index';
import { ConfigModule } from '@nestjs/config';
import * as dotenv from 'dotenv';
import { DbModule } from './db/db.module';
import { MenuController } from './modules/menu/menu.controller';
import { MenuService } from './modules/menu/menu.service';

// 方式一
// const { username, password } = getMySqlUserInfo();

// 方式二
const envPath = `.env.${process.env.NODE_ENV || 'development'}`;

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      envFilePath: envPath,
      // 这里新增.env的文件解析
      load: [() => dotenv.config({ path: '.env' })]
    }),
    DbModule,
    UserModule,
    AuthModule,
    BookModule
  ],
  controllers: [AppController, UserController, BookController, MenuController],
  providers: [AppService, MenuService]
})
export class AppModule {}
